package logic

import (
	"context"
	"shuqi-novel/api/internal/svc"
	"shuqi-novel/api/internal/types"
	"shuqi-novel/shuqirpc/shuqirpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type NovelAddApiLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewNovelAddApiLogic(ctx context.Context, svcCtx *svc.ServiceContext) *NovelAddApiLogic {
	return &NovelAddApiLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *NovelAddApiLogic) NovelAddApi(req *types.NovelAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	add, err := l.svcCtx.ShuqiRpc.NovelAdd(l.ctx, &shuqirpc.NovelAddRequest{
		Title:   req.Title,
		Content: req.Content,
		UserId:  req.UserId,
	})
	if err != nil {
		return &types.Response{
			Message: "添加失败",
			Code:    500,
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "添加成功",
		Code:    200,
		Data:    add,
	}, nil
}
